﻿using UnityEngine;

namespace Script.Audio
{
    public class EffectAudio : AudioBase
    {
        // Logic object
        private AudioSource audioSource;


        private void Awake()
        {
            Bind(AudioEvent.PLAY_EFFECT_AUDIO);
        }

        public override void Execute(int eventCode, object message)
        {
            switch (eventCode)
            {
                case AudioEvent.PLAY_EFFECT_AUDIO:
                    PlayerEffectAudio(message.ToString());
                    break;
                default:
                    Debug.Log("something is wrong");
                    break;
            }
        }

        private void Start()
        {
            audioSource = transform.GetComponent<AudioSource>();
        }

        /// <summary>
        /// 播放音乐
        /// </summary>
        /// <param name="assetName"></param>
        private void PlayerEffectAudio(string assetName)
        {
            AudioClip ac = Resources.Load<AudioClip>("Sound/" + assetName);

            Debug.Log(ac.name);

            audioSource.clip = ac;

            audioSource.Play();
        }
    }
}